package com.sbr.seb.wicket.page.tdb;

import java.util.List;

import org.apache.wicket.PageParameters;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.list.ListItem;
import org.apache.wicket.markup.html.list.ListView;
import org.apache.wicket.model.LoadableDetachableModel;
import org.apache.wicket.spring.injection.annot.SpringBean;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.sbr.seb.entity.composants.Item;
import com.sbr.seb.entity.composants.ItemValue;
import com.sbr.seb.planning.dao.CategoryDao;
import com.sbr.seb.wicket.menu.tdb.TableauDeBordSideMenu;
import com.sbr.seb.wicket.page.BasePage;


public class TableauDeBordBasePage extends BasePage {

	private static final Logger logger = LoggerFactory.getLogger(TableauDeBordBasePage.class);

	
	@SpringBean
	private CategoryDao categoryDao;
	
    public TableauDeBordBasePage(final PageParameters parameters) {
    	super();
    	
    	logger.debug("parameter = "+parameters);
    	
    	add(new TableauDeBordSideMenu("tdbSideMenu"));
    	
    	add(new Label("category", "OCANQ"));
    	add(new ListView<Item>("itemList", new LoadableDetachableModel<List<Item>>() {

			private static final long serialVersionUID = 1L;

			@Override
			protected List<Item> load() {
				return categoryDao.findItemsOfCategory(parameters.getInt("categoryId"));
			}
		}) {

			private static final long serialVersionUID = 1L;

			@Override
			protected void populateItem(ListItem<Item> item) {
				Item myItem = item.getModelObject();
				logger.debug("item : {}",myItem.getName());
				item.add(new Label("name", myItem.getName()));
//				item.add(new Label("description", myItem.getDescription()));
			}

    	});
    	add(new ListView<ItemValue>("itemValueList", new LoadableDetachableModel<List<ItemValue>>() {

			private static final long serialVersionUID = 1L;

			@Override
			protected List<ItemValue> load() {
				return categoryDao.findItemValuesOfCategory(parameters.getInt("categoryId"));
			}
		}) {

			private static final long serialVersionUID = 1L;

			@Override
			protected void populateItem(ListItem<ItemValue> item) {
				ItemValue value = item.getModelObject();
				logger.debug("item : {}",value.getValue());
				item.add(new Label("value", value.getValue()));
			}

    	});
    	
    	
    }
}
